<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/23
 * Time: 15:58
 */

namespace app\lib\exception;


use think\exception\Handle;
use think\facade\Log;

class ExceptionHandler extends Handle
{

    public $code = 400;
    public $msg = '';
    public $errorCode = 999;

    public function render(\Exception $ex){

        /*$a = new NotFoundException();

        //var_dump($a instanceof  BaseException);die;

        $ex = $a;*/

        if($ex instanceof BaseException){
            $this->code = $ex->code;
            $this->msg = $ex->msg;
            $this->errorCode = $ex->errorCode;
        }else{

            if(config('app_debug')){
                return parent::render($ex);
            }

            $this->code = '500';
            $this->msg = '服务器错误';
            $this->errorCode = 9999;
        }

        $result = [
            'msg'=>$this->msg,
            'error_code'=>$this->errorCode
        ];

        return json($result,$this->code);
    }

}